<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:include="css :: css">

</head>

<link href="/js/jquery.icheck/skins/square/blue.css" rel="stylesheet">
<link href="/css/bootstrap-toggle.min.css" rel="stylesheet">
<style>
    .block-flat .form-group {
        margin: 0 !important;
        padding: 0 !important;
    }
</style>
<body style="opacity: 1">
<div style="padding-top: 0">
    <div class="container-fluid">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-flat">
                        <form class="form-horizontal group-border-dashed" onsubmit="return false;" id="withdrawForm">
                            <div class="form-group">
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="会员编号/名称" id="queryAccount"
                                           name="account"/>
                                </div>
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="支付宝" id="queryAlipay"
                                           name="alipay"/>
                                </div>
                                <div class="input-group">
                                    <button class="btn btn-primary" type="button" id="search"><i
                                            class="fa fa-search"></i>查询
                                    </button>&nbsp;
                                    <button class="btn btn-success btn-operation" type="button"
                                            id="addTime"><i class="fa fa-plus-square-o"></i> 修改
                                    </button>&nbsp;
                                    <button class="btn btn-success btn-operation" type="button"
                                            id="deleteTime"><i class="fa fa-plus-square-o"></i> 关闭
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="block-flat">
                        <div class="content">
                            <div class="table-responsive">
                                <table class="table hover" id="dataTable">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="updateStatusLabel">
        <div class="modal-dialog" role="document" style="width:800px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="updateStatusLabel">修改支付宝</h4>
                </div>
                <div class="modal-body" style="min-height: 211px;">
                    <form class="form-horizontal" role="form" id="maintainForm">
                        <input type="hidden" id="alipayId" name="id">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label for="alipay" class="col-sm-4 control-label"><span
                                        class="text-danger"></span>会员编号:</label>
                                <div class="col-sm-7" style="width: 240px">
                                    <input type="text" class="form-control"
                                           id="account" name="account">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="alipay" class="col-sm-4 control-label"><span
                                        class="text-danger"></span>支付宝:</label>
                                <div class="col-sm-7" style="width: 240px">
                                    <input type="text" class="form-control"
                                           id="alipay" name="alipay">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="toSave">确定</button>
                </div>
            </div>
        </div>
    </div>

</div>

<div th:include="js :: js"></div>
<script type="text/javascript" th:attr="src=@{/js/jquery.form.js}"></script>
<script type="text/javascript" th:attr="src=@{/js/jquery.parser.js}"></script>
<script type="text/javascript" src="js/jquery.icheck/icheck.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var adminRole = roleCheck();
        $('#dataTable').bootstrapTable({
            url: '/AlipayConfigController/querySupAlipayDetail',
            height: $(window).height() - 200,
            pageSize: 30,
            pagination: true,
            pageList: [30, 50, 100],
            clickToSelect: true,
            queryParams: queryParams,
            singleSelect: true,
            uniqueId: 'id',
            queryParamsType: '',
            sidePagination: 'server',
            showFooter: true,
            responseHandler: function (res) {
                return {
                    "total": res.total,
                    "rows": res.resultList
                };
            },
            onClickRow: function (row) {
                if (row.account != null && row.account != '') {
                    $("#account_field" + row.id).html(row.account);
                }
            },
            columns: [
                {
                    checkbox: true
                },
                {
                    align: 'center',
                    formatter: function (v, row, index) {
                        return index + 1
                    }
                }, {align: 'center', field: 'id', visible: false},
                {
                    align: 'center', field: 'account', title: '会员编号',
                    formatter: function (v, o) {
                        return copyAddon(v) + (adminRole == 1 ? v : userAccountHidden(o.account, o.id));
                    }
                }, {
                    align: 'center', field: 'name', title: '会员名称'
                },
                {
                    align: 'center', field: 'alipay', title: '支付宝'
                }, {
                    align: 'center', field: 'isUse', title: '状态',
                    formatter: function (v, row, index) {
                        return bankState[v];
                    }
                },
                {
                    align: 'center', field: 'gmtCreate', title: '创建时间',
                    formatter: function (v, row, index) {
                        return format(v);
                    }
                },
                {
                    align: 'center', field: 'gmtModified', title: '修改时间',
                    formatter: function (v, row, index) {
                        return format(v);
                    }
                },
                {
                    align: 'center', field: 'remark', title: '备注'
                }
            ]
        });


        $("#search").click(function () {
            reloadData();
        });

        //重载数据
        function reloadData() {
            $("#dataTable").bootstrapTable("refresh");
        }


        $("#addTime").click(function () {
            var rows = $('#dataTable').bootstrapTable("getSelections");
            if (rows == null || rows.length === 0) {
                layer.msg("请选择要操作的订单");
                return;
            }
            $("#account").val(rows[0].account);
            $("#alipayId").val(rows[0].id);
            $("#alipay").val(rows[0].alipay);
            $("#account").attr("readOnly", true);
            $("#myModal1").modal("show");
        });

        $("#deleteTime").click(function () {
            var rows = $('#dataTable').bootstrapTable("getSelections");
            if (rows == null || rows.length === 0) {
                layer.msg("请选择要操作的数据");
                return;
            }
            var row = rows[0];
            $.confirm({
                title: '确认!',
                content: '确定关闭' + row.name + '绑定支付宝吗？',
                confirm: function () {
                    $.post("/AlipayConfigController/deleteSupAlipay?id="
                        + row.id, function (data) {
                        layer.msg(data.message);
                        $("#dataTable").bootstrapTable("refresh");
                    });
                },
                cancel: function () {

                }
            });
        })
    })
    $("#toSave").click(function () {
        if ($("#alipay").val() == '' || $("#alipayId").val() == '') {
            layer.msg("账号不可为空");
        }
        $.post("/AlipayConfigController/updateSupAlipay", $("#maintainForm").serialize(), function (data) {
            layer.msg(data.message);
            if (data.success) {
                $("#myModal1").modal("hide");
                $("#dataTable").bootstrapTable("refresh");
            }
        })


    })

    function queryParams(params) {
        return {
            size: params.pageSize,
            page: params.pageNumber,
            account: $("#queryAccount").val(),
            alipay: $("#queryAlipay").val()
        };
    }

</script>
</body>
</html>
